<script setup lang="ts">
import {reactive} from 'vue';
import {useRouter} from 'vue-router';
import {taskDetails, taskCollection} from '@/api/task';
import TaskDetail from './components/TaskDetail.vue'
import {Toast} from 'vant';
import {nmzpJobId} from "@/api/job"
import {sendResume} from "@/api/Resume"
import {addCollect} from "@/api/collect";

const router = useRouter()
const taskId = router.currentRoute.value.params.id
const state: any = reactive({
  item: '',
  status: 0,
  isSend: false,
  loading: false
})
const leftBack = () => history.back();
const gotoMessage = () => {
  router.push('/message/talk/'+ state.item.userId)
}
const getTaskDetail = async () => {
  state.loading = true
  nmzpJobId(taskId).then(res => {
    if (res.code == 200) {
      state.item = res.data
      state.loading = false
      console.log(state.item)
    } else {
      Toast(res.msg)
      state.loading = false
    }
  })
}
getTaskDetail()
const setTaskCollection = async () => {
  state.loading = true
  addCollect(taskId).then(res => {
    Toast(res.msg)
    state.loading = false
  })
}

const toSend = () => {
  sendResume({
    jobId: taskId
  }).then(res=>{
    if (res.data.code == 200){
      state.isSend = true
    }
    Toast(res.msg)
  })
}
</script>
<template>
  <van-nav-bar title="职位详情" left-arrow @click-left="leftBack"/>
  <TaskDetail :item="state.item" v-if="state.item"></TaskDetail>
  <div class="task-detail-footer">
    <van-action-bar-icon :class="state.status==1?'active':''" icon="star-o" text="收藏" @click="setTaskCollection"/>
    <van-button type="primary" block @click="toSend" v-if="!state.isSend">直接投递</van-button>
    <van-button type="primary" block @click="gotoMessage">立即沟通</van-button>
  </div>
</template>
<style scoped>
.task-detail-footer {
  display: flex;
  position: fixed;
  left: 0;
  width: 100%;
  align-items: center;
  background: #ffffff;
  bottom: 0;
  padding: 0.64rem 0;
}

.task-detail-footer button {
  margin-right: 0.64rem;
}

.task-detail-footer .active >>> .van-icon-star-o:before {
  color: #FE8F27;
}
</style>